//import vueAreaSelect from './components/vue-area-select'   //引入组件
//import scroll from './components/scroll1.vue'   //引入组件
import odd from './component/odd.vue'   //引入组件
// import 'font-awesome/css/font-awesome.css'
const oddbox = {
  install (Vue, options) {
//    Vue.component(vueAreaSelect.name, vueAreaSelect) //全局组件
//    Vue.component(scroll.name, scroll) //全局组件
   Vue.component(odd.name, odd) //全局组件
      Vue.prototype.$http=(obj={method:"GET",http:"http",url:"",data:{},wait:true,debug:false},options={})=>{
        if(obj.http="http"){
          let res=new Promise(function (resolve, reject) {
            let xhr=new XMLHttpRequest();
            xhr.open(obj.method, obj.url, obj.wait);
            xhr.send(obj.data);
            xhr.onreadystatechange = function () {
              if(obj.debug){
                switch(xhr.readyState){
                  case 0:
                    console.log("请求未初始化");
                    break;
                  case 1:
                    console.log("服务器连接已建立");
                    break;
                  case 2:
                   console.log("请求已接收");
                    break;
                  case 3:
                    console.log("请求处理中");
                    break;
                  case 4:
                    console.log("请求已完成，且响应已就绪");
                    if(xhr.status==200){
                      console.log(xhr.obj);
                      resolve(xhr.obj);
                    }else{
                     reject(xhr);
                    } 
                    break;
                }
              } else if (xhr.readyState==4){
                if(xhr.status==200){
                   resolve(xhr.obj);
                }else{
                  reject()
                } 
               }
                         
              }
          })
          return res;
        } else {
          
        }

      }
  }
}

export default oddbox  //导出
